<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>键盘事件</title>
</head>
<body>
<input type="text" onkeydown="downfn()" onkeyup="upfn()">

<script>
    function downfn(){
        //得到案件编码
        console.log("键盘按下:"+event.keyCode)
    }
    function upfn(){
        console.log("键盘抬起:"+String.fromCharCode(event.keyCode));
    }

</script>

</body>
</html>